package com.example.rocketmq.demo.consumer;

import com.example.rocketmq.demo.config.RocketMQConstant;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.annotation.SelectorType;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

/**
 * 基于注解方式的SQL属性过滤消息消费者
 */
@Slf4j
@Component
@RocketMQMessageListener(
        topic = RocketMQConstant.TOPIC_FILTER,
        consumerGroup = "annotation-sql-filter-consumer-group",
        selectorType = SelectorType.SQL92,
        selectorExpression = "age >= 18 AND age <= 30" // 只消费age属性在18-30之间的消息
)
public class AnnotationSQLFilterConsumer implements RocketMQListener<String> {

    @Override
    public void onMessage(String message) {
        log.info("注解方式-接收到SQL属性过滤消息: {}", message);
    }
}